const express = require('express')
const cors = require('cors')
const path = require('path')
const login = require(path.join(__dirname, 'routers', 'login.js'))
const db = require(path.join(__dirname, 'common', 'db.js'))

const app = express()

//从客户端请求post参数
//for parsing application/json
app.use(express.json())
//for parsing application/x-www-from-urlencoded
app.use(express.urlencoded({ extended: true }))

//设置跨域
app.use(cors())

//配置路由模块
app.use('/api', login)


app.get('/data', async (req, res) => {
    let sql = 'select * from user'
    // db.operateData(sql, null)
    //     .then((result) => {
    //         res.end(result)
    //     })
    let result = await db.operateData(sql)
    res.send(result)
})
//配置端口
app.listen(8888, () => {
    console.log('running....');
})